from tkinter import *
import tkinter.messagebox
import re


class MainWindow:
    def buttonListener1(self, event):
        data1 = self.text_parameter.get("0.0", "end")
        data2 = self.text_preparing.get("0.0", "end")
        data1 = re.split('\([\w\s]+\),\s', data1)
        data1[len(data1)-1] = re.sub('\(.*\)\\n', "", data1[len(data1)-1])
        print(data1)
        print(data2)
        j = 0
        ttsql = ''
        for s in data2:
            if s != '?':
                ttsql = ttsql + s
            else:
                ttsql = ttsql + '\'' + data1[j] + '\''
                j = j + 1
        print(ttsql)
        self.text_result.delete(0.0, tkinter.END)
        self.text_result.insert(INSERT, ttsql)

    def selectText_preparing(self, event):
        self.text_preparing.tag_add(tkinter.SEL, "1.0", tkinter.END)
        return 'break'

    def selectText_parameter(self, event):
        self.text_parameter.tag_add(tkinter.SEL, "1.0", tkinter.END)
        return 'break'

    def selectText_result(self, event):
        self.text_result.tag_add(tkinter.SEL, "1.0", tkinter.END)
        return 'break'

    def __init__(self):
        self.frame = Tk()
        self.frame.geometry("1024x768")

        self.label_parameter = Label(self.frame, text="Parameters:")
        self.label_preparing = Label(self.frame, text="Preparing:")
        self.label_result = Label(self.frame, text="Result:")

        self.text_parameter = Text(self.frame, height="8", width=100, background="grey", highlightbackground="orange")
        self.text_preparing = Text(self.frame, height="8", width=100, background="grey", highlightbackground="orange")
        self.text_result = Text(self.frame, height="14", width=100, background="grey")

        self.label_parameter.grid(row=0, column=0)
        self.label_preparing.grid(row=1, column=0)

        self.button_ok = Button(self.frame, text="ok", width=10)
        self.button_cancel = Button(self.frame, text="cancel", width=10)

        self.text_parameter.grid(row=0, column=1)
        self.text_preparing.grid(row=1, column=1)

        self.button_ok.grid(row=3, column=0)
        self.button_cancel.grid(row=3, column=1)
        self.label_result.grid(row=4, column=0)
        self.text_result.grid(row=4, column=1)

        self.button_ok.bind("<ButtonRelease-1>", self.buttonListener1)
        self.text_preparing.bind("<Command-Key-a>", self.selectText_preparing)
        self.text_result.bind("<Command-Key-a>", self.selectText_result)
        self.text_parameter.bind("<Command-Key-a>", self.selectText_parameter)

        self.frame.mainloop()


frame = MainWindow()
